package net.wangds.procengine.flow.define.node;

import lombok.Getter;
import lombok.Setter;
import net.wangds.procengine.ProcResEnum;
import net.wangds.procengine.flow.FlowContext;
import net.wangds.procengine.flow.define.FlowDef;
import net.wangds.procengine.flow.define.actor.ActorDef;
import net.wangds.procengine.flow.instance.actor.Actor;

import java.util.function.BiFunction;

/**
 * Java节点.
 * <p></p>
 *
 * @author 王东石 2020/9/8 10:44.
 */
public class JavaFlowNode extends AbstractFlowNode {

    /**
     * 空函数.
     */
    protected static final BiFunction<FlowContext, Actor, ProcResEnum> EMPTY_FUNC = (c,a)->ProcResEnum.CONTINUE;

    @Getter
    @Setter
    private BiFunction<FlowContext, Actor, ProcResEnum> func;

    public <A extends ActorDef> JavaFlowNode(FlowDef<A> flow, BiFunction<FlowContext, Actor, ProcResEnum> func, FlowNode previousNode){
        flow.addFlowNode(this);
        this.func = func;
        this.setType(FlowNodeTypeEnum.AUTO);
        if(previousNode!=null){
            previousNode.setNextId(this.getId());
        }
    }


    public <A extends ActorDef> JavaFlowNode(FlowDef<A> flow, FlowNode previousNode){
        this(flow, EMPTY_FUNC, previousNode);
    }


}
